home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 3 / Cream of the Crop 3.iso / utility / mu17_ext.zip / RLSERV.C < prev    next >
C/C++ Source or Header  |  1994-03-07  |  4KB  |  167 lines

  1. /*
  2. **    $VER: rlserv.c 1.1 (08.02.94)
  3. **
  4. **    rlogin.service functions
  5. **
  6. **    ⌐ Copyright 1994 by Norbert Pⁿschel
  7. **    All Rights Reserved
  8. */
  9.  
  10. #include <proto/exec.h>
  11. #include <proto/dos.h>
  12. #include <proto/utility.h>
  13. #include <clib/accounts_protos.h>
  14. #include <pragmas/accounts_pragmas.h>
  15. #include <clib/svc_protos.h>
  16. #include <pragmas/svc_pragmas.h>
  17.  
  18. #include <envoy/errors.h>
  19. #include <envoy/services.h>
  20. #include <dos/var.h>
  21. #include <dos/dostags.h>
  22.  
  23. #include <string.h>
  24.  
  25. #include <debug.h>
  26.  
  27. void __saveds __asm LIBGetServiceAttrsA(register __a0 struct TagItem *tags)
  28.  
  29. {
  30.   STRPTR name;
  31.  
  32.   name = (STRPTR)GetTagData(SVCAttrs_Name,0,tags);
  33.   if(name) strcpy(name,"Remote Login");
  34. }
  35.   
  36. void __saveds __asm LIBSetServiceAttrsA(register __a0 struct TagItem *tags)
  37.  
  38. {}
  39.  
  40. void __saveds __asm LIBAttemptShutdown(register __a0 STRPTR *why,
  41.                                        register __d0 ULONG when)
  42.  
  43. {}
  44.  
  45. extern void handler_func(void);
  46.  
  47. LONG getstr(BPTR fh,STRPTR buff,LONG len)
  48.  
  49. {
  50.   LONG c;
  51.  
  52.   while(--len > 0) {
  53.     c = FGetC(fh);
  54.     if(c == ',' || c == ' ' || c == '\t' || c == '\n' || c == -1) break;
  55.     *(buff++) = c;
  56.   }
  57.   *buff = '\0';
  58.   if(c == ' ' || c == '\t') c = '\n';
  59.   return(c);
  60. }
  61.  
  62. ULONG checkuser(STRPTR uname,STRPTR pwd)
  63.  
  64. {
  65.   struct Library *AccountsBase;
  66.   struct UserInfo *user;
  67.   struct GroupInfo *group;
  68.   ULONG retval = ENVOYERR_NORESOURCES;
  69.   BPTR prefs;
  70.   LONG c;
  71.  
  72.   AccountsBase = OpenLibrary("accounts.library",37);
  73.   if(AccountsBase) {
  74.     user = AllocUserInfo();
  75.     if(user) {
  76.       retval = VerifyUser(uname,pwd,user);
  77.       debug2("rlogin.service: VerifyUser: %ld\n",retval);
  78.       if(retval == 0) {
  79.         prefs = Open("ENV:Envoy/rlogin.prefs",MODE_OLDFILE);
  80.         if(prefs) {
  81.           do {
  82.             c = getstr(prefs,user->ui_UserName,32);
  83.             if(user->ui_UserID) {
  84.               retval = strcmp(uname,user->ui_UserName);
  85.             }
  86.             else {
  87.               retval = Stricmp("nobody",user->ui_UserName);
  88.             }
  89.             if(retval == 0) break;
  90.           } while(c != '\n' && c != -1);
  91.           if(retval && c != -1) {
  92.             group = AllocGroupInfo();
  93.             if(group) {
  94.               strcpy(user->ui_UserName,uname); /* restore userinfo */
  95.               do {
  96.                 c = getstr(prefs,group->gi_GroupName,32);
  97.                 group->gi_GroupID = 0;
  98.                 retval = MemberOf(group,user);
  99.                 if(retval == 0) break;
  100.               } while(c != '\n' && c != -1);
  101.               FreeGroupInfo(group);
  102.               if(retval) retval = ENVOYERR_UNKNOWNMEMBER;
  103.             }
  104.             else retval = ENVOYERR_NORESOURCES;
  105.           }
  106.           Close(prefs);
  107.         }
  108.         else retval = ENVOYERR_NORESOURCES;
  109.       }
  110.       FreeUserInfo(user);
  111.     }
  112.     CloseLibrary(AccountsBase);
  113.   }
  114.   return(retval);
  115. }
  116.  
  117. /* handler startup packet:
  118.  
  119.    Arg1 = user name
  120.    Arg2 = password
  121.    Arg3 = host name
  122.    Arg4 = entity name buffer
  123.  
  124. */
  125.  
  126. ULONG __saveds __asm LIBStartServiceA(register __a0 struct TagItem *tags)
  127.  
  128. {
  129.   ULONG retval;
  130.   struct Process *handler;
  131.   STRPTR uname,pwd,ename,hname;
  132.  
  133.   debug("StartService\n");
  134.  
  135.   uname = (STRPTR)GetTagData(SSVC_UserName,0,tags);
  136.   pwd   = (STRPTR)GetTagData(SSVC_Password,0,tags);
  137.   hname = (STRPTR)GetTagData(SSVC_HostName,0,tags);
  138.   ename = (STRPTR)GetTagData(SSVC_EntityName,0,tags);
  139.  
  140.   if(uname == 0 || pwd == 0 || hname == 0 || ename == 0) {
  141.     return(ENVOYERR_NULLPTR);
  142.   }
  143.  
  144.   if(retval = checkuser(uname,pwd)) return(retval);
  145.  
  146.   debug("Checkuser OK\n");
  147.  
  148.   handler = CreateNewProcTags(NP_Entry,handler_func,
  149.                               NP_Name,"Remote Shell Handler",
  150.                               NP_Priority,0,
  151.                               NP_WindowPtr,-1,
  152.                               NP_Cli,TRUE,
  153.                               TAG_DONE);
  154.  
  155.   if(handler) {
  156.     debug("Handler created\n");
  157.     if(!DoPkt4(&(handler->pr_MsgPort),0,(LONG)uname,(LONG)pwd,
  158.        (LONG)hname,(LONG)ename)) {
  159.       retval = IoErr();
  160.       debug2("Handler failed: %ld\n",retval);
  161.     }
  162.   }
  163.   else retval = ENVOYERR_NORESOURCES;
  164.  
  165.   return(retval);
  166. }
  167.